package com.oly.cms.comment.web.listener;

import com.oly.cms.comment.web.event.CommentReplyEvent;
import com.oly.cms.comment.web.model.CmsComment;
import com.ruoyi.mail.domain.OlyMail;
import com.ruoyi.mail.service.impl.OlyMailServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class SendMailEventListen {
    @Autowired
    private OlyMailServiceImpl mailService;

    /**
     * 评论生效发送
     * 
     * @param event
     */
    @EventListener
    protected void handleVisitEvent(CommentReplyEvent event) {
        OlyMail olyMail = new OlyMail();

        CmsComment cmsComment = event.getCmsComment();
        olyMail.setSubject("你的在XXX网站的评论已经生效");
        olyMail.setContent("你的在XXX网站的评论已经生效:" + cmsComment.getContent());
        olyMail.setFromMail(cmsComment.getFromEmail());
        mailService.sendHtmlMail(olyMail, false);
        if (cmsComment.getReplyBy() != null) {
            olyMail.setSubject("你在XXX网站的评论有了新回复");
            olyMail.setContent("你在XXX网站的评论有了新回复:" + cmsComment.getContent());
            olyMail.setFromMail(cmsComment.getReplyEmail());
            mailService.sendHtmlMail(olyMail, false);
        }
    }
}
